package com.zyxx.common.mybatis;

import com.baomidou.mybatisplus.core.config.GlobalConfig;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * mybatisplus配置类
 *
 * @Author Lizhou
 */
@Configuration
@MapperScan("com.zyxx.*.mapper")
public class MybatisPlusConfig {

	/**
	 * 自动填充功能
	 *
	 * @return
	 */
	@Bean
	public GlobalConfig globalConfig() {
		GlobalConfig globalConfig = new GlobalConfig();
		globalConfig.setMetaObjectHandler(new MetaHandler());
		return globalConfig;
	}


	/**
	 * 分页插件
	 */
	@Bean
	public PaginationInterceptor paginationInterceptor() {
		PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
		paginationInterceptor.setLimit(Integer.MAX_VALUE);
		return paginationInterceptor;
	}

	/**
	 * 数据权限
	 *
	 * @return
	 */
	@Bean
	public DataScopePluginInterceptor dataPluginInterceptor() {
		return new DataScopePluginInterceptor();
	}
}
